import inspect
import datetime
import types
import time
from google.appengine.ext import db
def getDict(obj):
    dic = dict()
    for name in dir(obj) :
        if(name.startswith("_",0,1)):
            continue
        value = getattr(obj,name)
        if(inspect.ismethod(value)==False):
            dic[name] = value
    key = obj.key()
    #if callable(key):
    if(dir(key).count("id")>0):
        dic["id"] = key.id()
    return dic

def getDicts(objs):
    arr = []
    for obj in objs:
        arr.append(getDict(obj))
    return arr;

def mergeBean(org,new):
    for name in org:
        if(dir(new).count(name)>0):
            setattr(new, name,org[name])

        #
        
        #if(callable(obj)):
        #    obj = org[name]
        
def stringToDate(value):
    date = time.strptime(value,"%Y-%m-%d")
    d4 = datetime.datetime(date[0], date[1],date[2]) 
    return d4.date()